home *** CD-ROM | disk | FTP | other *** search
- #include "hm.h"
-
-
- unsigned char walls[] = {
- 0, 1, 3, 0, // 0
- 2, 0, 1, 1, // 1
- 1, 2, 2, 3, // 2
- 3, 3, 0, 2, // 3
- };
-
- #define WORLDSIZE 16384
- #define START_PHASE 0
-
- void drawButton(short button, Boolean hilite);
- Rect buttonRect(short button);
- void trackButton(Point where, short button, short hOffset, short vOffset);
- void drawMaze(Rect r, Rect world, Rect locationRect, short phase);
-
-
- Rect buttonRect(short button)
- {
- Rect r = {0, 0, 32, 32};
- Point location;
- switch (button) {
- case 0: case 4:
- location.h = ICON_MARGIN;
- location.v = (height(mazeWindow->portRect) - ICON_SIZE) / 2;
- break;
-
- case 1: case 5:
- location.h = (width(mazeWindow->portRect) - ICON_SIZE) / 2;
- location.v = mazeWindow->portRect.bottom - ICON_SIZE - ICON_MARGIN;
- break;
-
- case 2: case 6:
- location.h = mazeWindow->portRect.right - ICON_SIZE - ICON_MARGIN;
- location.v = (height(mazeWindow->portRect) - ICON_SIZE) / 2;
- break;
-
- case 3: case 7:
- location.h = (width(mazeWindow->portRect) - ICON_SIZE) / 2;
- location.v = ICON_MARGIN;
- break;
- }
- OffsetRect(&r, location.h, location.v);
- return r;
- }
-
-
- void drawButton(short button, Boolean hilite)
- {
- BitMap iconBits;
- Handle icon = GetResource('ICON', button + (hilite ? ICON_HiLeft : ICON_Left));
- Rect r = buttonRect(button);
-
- HLock(icon);
- iconBits.baseAddr = *icon;
- iconBits.rowBytes = 4;
- iconBits.bounds.left = 0;
- iconBits.bounds.top = 0;
- iconBits.bounds.right = 32;
- iconBits.bounds.bottom = 32;
-
- CopyBits(&iconBits, &mazeWindow->portBits, &iconBits.bounds, &r, srcCopy, 0);
- HUnlock(icon);
- }
-
-
- void drawMaze(Rect r, Rect world, Rect locationRect, short phase)
- {
- Rect result;
- if (SectRect(&locationRect, &world, &result)) {
- short size = (short)(((unsigned long)world.right - (unsigned long)world.left) / 2);
- if (size <= MAZE_LIMIT) {
- OffsetRect(&world, r.left - locationRect.left, r.top - locationRect.top);
- MoveTo(world.left + size, world.top + size);
- switch (phase) {
- case 0:
- LineTo(world.left + size, world.bottom);
-
- MoveTo(world.left, world.top + size);
- LineTo(world.left, world.top);
- LineTo(world.right, world.top);
- LineTo(world.right, world.top + size);
- break;
-
- case 1:
- LineTo(world.left, world.top + size);
-
- MoveTo(world.left + size, world.top);
- LineTo(world.right, world.top);
- LineTo(world.right, world.bottom);
- LineTo(world.left + size, world.bottom);
- break;
-
- case 2:
- LineTo(world.left + size, world.top);
-
- MoveTo(world.left, world.top + size);
- LineTo(world.left, world.bottom);
- LineTo(world.right, world.bottom);
- LineTo(world.right, world.top + size);
- break;
-
- case 3:
- LineTo(world.right, world.top + size);
-
- MoveTo(world.left + size, world.top);
- LineTo(world.left, world.top);
- LineTo(world.left, world.bottom);
- LineTo(world.left + size, world.bottom);
- break;
- }
- } else {
- unsigned char *pWall = walls + 4 * phase;
- short quarter = size / 2;
- Rect frame = world;
-
- OffsetRect(&frame, r.left - locationRect.left, r.top - locationRect.top);
- switch (phase) {
- case 0: case 2:
- MoveTo(frame.left, frame.top + quarter);
- LineTo(frame.left, frame.top + quarter + size);
- MoveTo(frame.right, frame.top + quarter);
- LineTo(frame.right, frame.top + quarter + size);
- break;
-
- case 1: case 3:
- MoveTo(frame.left + quarter, frame.top);
- LineTo(frame.left + quarter + size, frame.top);
- MoveTo(frame.left + quarter, frame.bottom);
- LineTo(frame.left + quarter + size, frame.bottom);
- break;
- }
-
-
- world.right -= size;
- world.bottom -= size;
- drawMaze(r, world, locationRect, *pWall++);
-
- OffsetRect(&world, 0, size);
- drawMaze(r, world, locationRect, *pWall++);
-
- OffsetRect(&world, size, 0);
- drawMaze(r, world, locationRect, *pWall++);
-
- OffsetRect(&world, 0, -size);
- drawMaze(r, world, locationRect, *pWall++);
- }
- }
- }
-
-
- void doMazeDraw(void)
- {
- Rect locationRect;
- Rect world = {-WORLDSIZE, -WORLDSIZE, WORLDSIZE, WORLDSIZE};
- Rect r = {-15, -15, 0, 0};
-
- OffsetRect(&r, mazeWindow->portRect.right, mazeWindow->portRect.bottom);
- EraseRect(&mazeWindow->portRect);
- GetClip(scratchRgn);
- ClipRect(&r);
- DrawGrowIcon(mazeWindow);
- r = mazeWindow->portRect;
- InsetRect(&r, ICON_SIZE + ICON_MARGIN * 2, ICON_SIZE + ICON_MARGIN * 2);
- ClipRect(&r);
-
- locationRect = r;
- OffsetRect(&locationRect, location.h - locationRect.left, location.v - locationRect.top);
- InsetRect(&locationRect, -1, -1);
- drawMaze(r, world, locationRect, START_PHASE);
- SetClip(scratchRgn);
- InsetRect(&r, -1, -1);
- FrameRect(&r);
-
- drawButton(0, false);
- drawButton(1, false);
- drawButton(2, false);
- drawButton(3, false);
- }
-
-
- void trackButton(Point where, short button, short hOffset, short vOffset)
- {
- Rect locationRect;
- Rect world = {-WORLDSIZE, -WORLDSIZE, WORLDSIZE, WORLDSIZE};
- Rect r = buttonRect(button);
- Rect inside = mazeWindow->portRect;
- Boolean stillInside;
- Boolean wasInside = false;
- InsetRect(&inside, ICON_SIZE + ICON_MARGIN * 2, ICON_SIZE + ICON_MARGIN * 2);
- GetClip(scratchRgn);
-
- do {
- stillInside = PtInRect(where, &r);
- if (stillInside != wasInside) {
- wasInside = stillInside;
- drawButton(button, stillInside);
- }
- if (stillInside) {
- location.h -= hOffset;
- location.v -= vOffset;
- ScrollRect(&inside, hOffset, vOffset, scrollRgn);
- SetClip(scrollRgn);
- locationRect = H(scrollRgn).rgnBBox;
- InsetRect(&locationRect, -1, -1);
- OffsetRect(&locationRect, location.h - inside.left, location.v - inside.top);
- drawMaze(H(scrollRgn).rgnBBox, world, locationRect, START_PHASE);
- //PaintRect(&inside);
- SetClip(scratchRgn);
- }
- GetMouse(&where);
- } while (StillDown());
- if (stillInside) {
- drawButton(button, false);
- }
- }
-
-
- void doMazeClick(Point where, short modifiers)
- {
- Rect r;
-
- r = buttonRect(0);
- if (PtInRect(where, &r)) {
- trackButton(where, 0, SCROLL, 0);
- } else {
- r = buttonRect(1);
- if (PtInRect(where, &r)) {
- trackButton(where, 1, 0, -SCROLL);
- } else {
- r = buttonRect(2);
- if (PtInRect(where, &r)) {
- trackButton(where, 2, -SCROLL, 0);
- } else {
- r = buttonRect(3);
- if (PtInRect(where, &r)) {
- trackButton(where, 3, 0, SCROLL);
- }
- }
- }
- }
- }